import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import javax.annotation.PostConstruct;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import javax.faces.model.DataModel;
import javax.faces.model.ListDataModel;
import javax.faces.model.SelectItem;

import org.primefaces.model.DualListModel;



@ManagedBean(name="ctfamily")
@SessionScoped
public class FileFamily {
	
	private List<Member> listMember;
	private DataModel<Member> modelTableListMember;
	private Member newMember;
	private Member selectedMember;
	private Risk selectedRisk;
	private RisksFamily newRisksFamily;
	private List<SelectItem> riskItems;
	private List<RisksFamily> listRiskFamily;
	private DataModel<RisksFamily> modelTableListRiskFamily;
	private Date newDateForFamilyRisk;
	private DualListModel<String> homeAppliancesSource;
	private List<String> homeAppliancesChosen;
	private DualListModel<String> aroundRiskSource;
	private List<String> aroundRiskChosen;
	
	@PostConstruct
	public void init(){
		newMember = new Member();
		selectedMember = new Member();
		listMember = new ArrayList<Member>();
		listRiskFamily = new ArrayList<RisksFamily>();
		modelTableListMember = new ListDataModel<Member>(listMember); 
		modelTableListRiskFamily = new ListDataModel<RisksFamily>(listRiskFamily);
		selectedRisk = new Risk();
		newRisksFamily = new RisksFamily();
		riskItems = Repository.allRiskSelectItem;
		homeAppliancesChosen = new ArrayList<String>();
		homeAppliancesSource = new DualListModel<String>(Repository.allHomeAppliances, homeAppliancesChosen);
		aroundRiskChosen = new ArrayList<String>();
		aroundRiskSource = new DualListModel<String>(Repository.allAroundRisk, aroundRiskChosen);
	}
	
	
	public void addNewMember(){
		System.out.println(newMember.toString());
		listMember.add(newMember);
		newMember = new Member();
	}
	
	public void actionSaveChanges(){
		System.out.println("Se guardaron los cambios");
		selectedMember = new Member();
	}
	
	public void actionSelectMember(){
		
		selectedMember = modelTableListMember.getRowData();
		System.out.println("Se ha seleccionado a :"+ selectedMember.getNombre());
	}
	
	public void actionAddRisk(){		
		newRisksFamily.setRisk(Repository.getRisk(selectedRisk.getId()));
		newRisksFamily.getDates().add(new Date());
		listRiskFamily.add(newRisksFamily);
		newRisksFamily = new RisksFamily();
		
		Repository.allRisk.remove(selectedRisk.getId());
		riskItems = Repository.allRiskSelectItem;
		
	}
	
	public void actionSelectRiskFamily(){
		newRisksFamily = modelTableListRiskFamily.getRowData();
	}
	
	public void addDateToFamilyRisk(){
		newRisksFamily.getDates().add(newDateForFamilyRisk);
		newDateForFamilyRisk = null;
	}
	
	public void addObservationToFamilyRisk(){
		newDateForFamilyRisk = null;
	}
	
	public String retornar1(){
		return "access?faces-redirect=true";
	}
	
	public String retornar2(){
		return "access?faces-redirect=true";
	}

	public List<Member> getListMember() {
		return listMember;
	}

	public void setListMember(List<Member> listMember) {
		this.listMember = listMember;
	}

	public DataModel<Member> getModelTableListMember() {
		return modelTableListMember;
	}

	public void setModelTableListMember(DataModel<Member> modelTableListMember) {
		this.modelTableListMember = modelTableListMember;
	}

	public Member getNewMember() {
		return newMember;
	}

	public void setNewMember(Member newMember) {
		this.newMember = newMember;
	}

	public Member getSelectedMember() {
		return selectedMember;
	}

	public void setSelectedMember(Member selectedMember) {
		this.selectedMember = selectedMember;
	}


	public Risk getSelectedRisk() {
		return selectedRisk;
	}


	public void setSelectedRisk(Risk selectedRisk) {
		this.selectedRisk = selectedRisk;
	}


	public List<SelectItem> getRiskItems() {
		return riskItems;
	}


	public void setRiskItems(List<SelectItem> riskItems) {
		this.riskItems = riskItems;
	}


	public RisksFamily getNewRisksFamily() {
		return newRisksFamily;
	}


	public void setNewRisksFamily(RisksFamily newRisksFamily) {
		this.newRisksFamily = newRisksFamily;
	}


	public List<RisksFamily> getListRiskFamily() {
		return listRiskFamily;
	}


	public void setListRiskFamily(List<RisksFamily> listRiskFamily) {
		this.listRiskFamily = listRiskFamily;
	}


	public DataModel<RisksFamily> getModelTableListRiskFamily() {
		return modelTableListRiskFamily;
	}


	public void setModelTableListRiskFamily(
			DataModel<RisksFamily> modelTableListRiskFamily) {
		this.modelTableListRiskFamily = modelTableListRiskFamily;
	}


	public Date getNewDateForFamilyRisk() {
		return newDateForFamilyRisk;
	}


	public void setNewDateForFamilyRisk(Date newDateForFamilyRisk) {
		this.newDateForFamilyRisk = newDateForFamilyRisk;
	}


	public DualListModel<String> getHomeAppliancesSource() {
		return homeAppliancesSource;
	}


	public void setHomeAppliancesSource(DualListModel<String> homeAppliancesSource) {
		this.homeAppliancesSource = homeAppliancesSource;
	}


	public List<String> getHomeAppliancesChosen() {
		return homeAppliancesChosen;
	}


	public void setHomeAppliancesChosen(List<String> homeAppliancesChosen) {
		this.homeAppliancesChosen = homeAppliancesChosen;
	}


	public DualListModel<String> getAroundRiskSource() {
		return aroundRiskSource;
	}


	public void setAroundRiskSource(DualListModel<String> aroundRiskSource) {
		this.aroundRiskSource = aroundRiskSource;
	}


	public List<String> getAroundRiskChosen() {
		return aroundRiskChosen;
	}


	public void setAroundRiskChosen(List<String> aroundRiskChosen) {
		this.aroundRiskChosen = aroundRiskChosen;
	}

	
	
}
